﻿Public Class frmUsuarioLista

    Private Sub frmMantenimientoBasicoLista_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Refrescar()
    End Sub
    Private Sub bntRefrescar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntRefrescar.Click

        Refrescar()
    End Sub

    Sub Refrescar()
        Dim UsuariosBS As Banco.BS.Usuarios
        UsuariosBS = New Banco.BS.Usuarios
        Me.dgLista.DataSource = UsuariosBS.Listar()
    End Sub

    Private Sub bntAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntAgregar.Click
        Dim mantenimiento As MantenimientoInsertar
        mantenimiento = New MantenimientoInsertar
        mantenimiento.ShowDialog()
        Refrescar()
    End Sub


    Private Sub bntEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntEditar.Click

        Dim id As Integer

        If dgLista.SelectedRows.Count = 1 Then

            Dim dgvRow As DataGridViewRow

            For Each dgvRow In dgLista.SelectedRows

                id = dgvRow.Cells(0).Value

            Next
            Dim mantenimiento As MantenimientoEditar
            mantenimiento = New MantenimientoEditar
            mantenimiento.Id = id
            mantenimiento.ShowDialog()
            Refrescar()
        Else

            MessageBox.Show("Debes seleccionar una fila")
        End If


    End Sub

    Private Sub bntEditarEstado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntEditarEstado.Click
        Dim id As Integer

        If dgLista.SelectedRows.Count = 1 Then

            Dim dgvRow As DataGridViewRow

            For Each dgvRow In dgLista.SelectedRows

                id = dgvRow.Cells(0).Value

            Next
            Dim mantenimiento As MantenimientoEditarEstados
            mantenimiento = New MantenimientoEditarEstados
            mantenimiento.Id = id
            mantenimiento.ShowDialog()
            Refrescar()
        Else

            MessageBox.Show("Debes seleccionar una fila")
        End If
    End Sub

    Private Sub bntBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntBuscar.Click
        Dim lista As New frmFiltros
        lista.ShowDialog()
    End Sub
End Class